package com.example.littleSpider.myapplication.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.base.BaseActivity;
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.lcodecore.tkrefreshlayout.header.progresslayout.ProgressLayout;
import com.littlespider.mylibrary.util.Print;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by aduser on 2017/12/7.
 */

public class ActivityTwo extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.list_view)
    ListView mListView;
    @BindView(R.id.refresh_view)
    TwinklingRefreshLayout refreshView;
//
//
//   @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_two);
//        ButterKnife.bind(this);
////        setSupportActionBar(toolbar);
//    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_two;
    }

    @Override
    protected void initView() {
        toolbar.setBackgroundColor(Color.parseColor("#cc222222"));
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        mListView.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return 2;
            }

            @Override
            public Object getItem(int position) {
                return null;
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                convertView = LayoutInflater.from(ActivityTwo.this).inflate(R.layout.item_especially_sale, null);
                return convertView;
            }
        });
        refreshView.setOnRefreshListener(new RefreshListenerAdapter() {
            @Override
            public void onRefresh(TwinklingRefreshLayout refreshLayout) {
                super.onRefresh(refreshLayout);
                Print.i("刷新");
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        refreshView.finishRefreshing();
                    }
                }, 2000);
            }

            @Override
            public void onLoadMore(TwinklingRefreshLayout refreshLayout) {
                super.onLoadMore(refreshLayout);
                Print.i("加载");
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        refreshView.finishLoadmore();
                    }
                }, 2000);
            }
        });
//        refreshView.setEnableRefresh(false);
//        refreshView.setEnableLoadmore(false);
        refreshView.setPureScrollModeOn();
//        refreshView.setHeaderView(new ProgressLayout(this));
//        refreshView.setFloatRefresh(true);
//        setActionBar(toolbar);

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        if (savedInstanceState != null){
            String s = savedInstanceState.getString("yesterday");
            Print.i("" + s);
        }
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.exit(0);
            }
        });
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        outState.putString("yesterday", "昨天");
    }

//    public void myClick(View view){
//        System.exit(0);
//    }
}
